package Practice6_Internet.P4_URL;

import Utils.io.IOUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class PT {
    @Test
    public void test01() throws MalformedURLException {
        URL url = new URL("https://gitee.com/static/images/logo-black.svg?t=158106664");
        System.out.println(url.getProtocol());  // https
        System.out.println(url.getHost());      // gitee.com
        System.out.println(url.getPort());      // -1
        System.out.println(url.getPath());      // /static/images/logo-black.svg
        System.out.println(url.getFile());      // /static/images/logo-black.svg?t=158106664
        System.out.println(url.getQuery());     // t=158106664
    }

    @Test
    public void test02() throws IOException {
        URL url = new URL("https://gitee.com/static/images/logo-black.svg?t=158106664");
        HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
        urlCon.connect();
        try (InputStream is = urlCon.getInputStream();) {
            IOUtils.inputStream2File(is,"D:\\个人文件\\计算机\\Java\\练习\\test.svg");
        }
    }
}